# ==========================用户修改区========================
# 编译工具
CC=gcc
# 编译参数
CFLAGS=-fPIC -Wall -c
# 外部库路径及链接的库
LDFLAGS=-L./libs 
LIBS=-lcrypto
# 输出目标名（最后输出的可执行文件名）
TARGET=rsatest
# 输出目标存放的路径（需要输出可执行文件存放的路径）
TARGET_FOLDER=.
# 源文件路径(根据实际修改)
SRC_PATH=./src
# 头文件路径(根据需要增删路径)
INCLUDES=./src
#生成.o文件的目录
OBJ_FOLDER=./obj
# 生成.so文件的目录
LIBS_FOLDER=.
# 定义全局宏(根据需要增删宏)
DEFINES= DEBUG=0
# 安装路径
PREFIX=./install
# service跟脚本路径
SERVICE_PATH=./system

#============================================================

# 编译成库
TARGETSO=lib$(TARGET).so

SOURCE_FILES_C= $(wildcard $(SRC_PATH)/*.c)
SOURCE_FILES_CXX= $(wildcard $(SRC_PATH)/*.cpp)
PURE_SOURCE_FILES= $(notdir $(SOURCE_FILES_C)) $(notdir $(SOURCE_FILES_CXX))

INCLUDE_PREFIX=-I#前缀
ALL_INCLUDES=$(addprefix $(INCLUDE_PREFIX), $(INCLUDES))

# 生成.o的文件
OBJ_FILES_C = $(patsubst %.c,$(OBJ_FOLDER)/%.o,$(PURE_SOURCE_FILES))
OBJ_FILES = $(patsubst %.cpp,$(OBJ_FOLDER)/%.o,$(OBJ_FILES_C))

DEFINE_PREFIX=-D#前缀
ALL_DEFINES=$(addprefix $(DEFINE_PREFIX), $(DEFINES))

# 这块就把源文件编译成o文件,可能是因为目标不是一个确定的内容或者单个内容，所以这里不会被直接执行
$(OBJ_FOLDER)/%.o : $(SRC_PATH)/%.c
	$(CC) $(ALL_DEFINES) $(ALL_INCLUDES) $(LDFLAGS) $(CFLAGS) $< -o $@
$(OBJ_FOLDER)/%.o : $(SRC_PATH)/%.cpp
	$(CC) $(ALL_DEFINES) $(ALL_INCLUDES) $(LDFLAGS) $(CFLAGS) $< -o $@

.PHONY :all clean lib install service

all:prep create

prep:
	@if test ! -d $(OBJ_FOLDER); then mkdir $(OBJ_FOLDER); fi	
	@if test ! -d $(TARGET_FOLDER); then mkdir $(TARGET_FOLDER); fi
	@if test ! -d $(LIBS_FOLDER); then mkdir $(LIBS_FOLDER); fi

create:$(OBJ_FILES)	
	$(CC) $(LDFLAGS) -o $(TARGET_FOLDER)/$(TARGET) $(OBJ_FILES) $(LIBS)

show:
	@echo $(OBJ_FILES)

lib:prep $(OBJ_FILES)
	$(CC) -shared -fPIC $(LDFLAGS) -o $(LIBS_FOLDER)/$(TARGETSO) $(OBJ_FILES) $(LIBS)

install:all lib
	@echo "not support"

service:all lib
	@echo "not support"

clean:
	rm -f $(OBJ_FOLDER)/*.o
	rm -f $(TARGET_FOLDER)/$(TARGET) $(LIBS_FOLDER)/$(TARGETSO)



